package com.browsesoft.parameter;

import java.util.Hashtable;

import com.browsesoft.dbtools.DBTools;

/**
 * 参数值
 */
public class ParameterValue {
	/**
	 * 存放属性值 参数值ID,参数值名称,参数值所属参数的id
	 */
	private Hashtable attributes = new Hashtable();

	/**
	 * 默认构造
	 */
	public ParameterValue() {
	}

	public ParameterValue(Hashtable attrs) {
		this.attributes = attrs;
	}

	public ParameterValue(String id) {
		try {
			// 生成参数
			String[][] param = DBTools
					.executeQueryWithTableHead("select * from t_paramvalue where id='"
							+ id + "'");
			attributes = DBTools.getAttributes(param, 1);
		} catch (Exception e) {
			System.out.println("参数值:" + id + "错误");
		}
	}

	/**
	 * 得到参数值属性
	 * 
	 * @return 属性
	 */
	public Hashtable getAttributes() {
		return this.attributes;
	}

	/**
	 * 转换成字符串
	 */
	public String toString() {
		return (String) this.attributes.get("name");
	}

	/**
	 * 转换成字符串
	 */
	public String toString(String s) {
		return (String) this.attributes.get(s);
	}

	/**
	 * 得到参数值名称
	 * 
	 * @return 参数值名称
	 */
	public String getName() {
		return (String) this.attributes.get("name");
	}

	/**
	 * 删除
	 */
	public void delete() throws Exception {
		String id = (String) this.getAttributes().get("id");
		String sql = "delete from t_paramvalue where id='" + id + "'";
		DBTools.excuteUpdate(sql);
	}

	public Parameter getParameter() throws Exception {
		String id = (String) this.getAttributes().get("processid");
		String sql = "select name from t_parameter where id='" + id + "'";
		String[][] data = DBTools.executeQueryWithTableHead(sql);
		String name = data[1][0];
		return Parameter.getParameter(name);
	}
}